import {createSlice}  from "@reduxjs/toolkit"
// 创建切片对象
let zanSlice = createSlice({
    name:"zan",
    initialState:{
        value:10
    },
    reducers:{
        zanadd:(state,action)=>{
            state.value+=action.payload

        },
        zansubtract:(state,action)=>{
            state.value-=action.payload

        }

    }

})
 export let {zanadd,zansubtract} = zanSlice.actions
// 异步加
export let asynaddzan = (payload)=>{
    return (dispatch)=>{
        dispatch(zanadd(payload))


    }
}

// 异步减
export  let asynsubtractzan = (payload)=>{
    return (dispatch)=>{
        dispatch(zansubtract(payload))
    }
}


export default zanSlice.reducer